<template>
  <Modal
    v-model:active="MidSurfaceModalVueActive"
    transfer
    title="创建中面"
    :width="480"
    :height="400"
    confirm-text="应用"
    hide-mask
    draggable
    :mask-close="false"
    :loading="loading"
    @confirm="executeMidSurface"
  >
    <NativeScroll use-y-bar height="100%" scroll-style="padding: 24px;">
      <Row :gap="[8]">
        <ConfigProvider :props="providedProps">
          <Form :model="formModel">
            <Column :span="24">
              <div class="title">
                <div class="title_color"></div>
                <div class="title_content">选择器</div>
              </div>
            </Column>
            <Column :span="8" :offset="4">
              <FormItem label="类型" action>
                <Button type="primary" @click="executeChoosePart">
                  选择实体
                </Button>
              </FormItem>
            </Column>
            <Divider></Divider>
            <Column :span="24">
              <div class="title">
                <div class="title_color"></div>
                <div class="title_content">选项</div>
              </div>
            </Column>
            <Column :span="18" :offset="6">
              <FormItem label="中面位置:" prop="input" :required="true">
                <Input
                  placeholder="中面位置"
                  v-model:value="formModel.midLocation"
                />
              </FormItem>
            </Column>
            <Column :span="18" :offset="6">
              <FormItem label="最大偏移量:" prop="input" :required="true">
                <Input
                  placeholder="最大偏移量"
                  v-model:value="formModel.midMaxoffset"
                />
              </FormItem>
            </Column>
          </Form>
        </ConfigProvider>
      </Row>
    </NativeScroll>
  </Modal>
</template>
<script setup lang="ts">
import { ref, reactive } from "vue";
import {
  Button,
  Modal,
  Select,
  Divider,
  Form,
  FormItem,
  ConfigProvider,
  Input,
  Checkbox,
  NativeScroll,
  Row,
  Column,
  Toast,
  Message,
} from "cax-ui";
import { storeToRefs } from "pinia";
import { SelectedParts } from "@/FrontProcessing";
import { useCoreStore, _global } from "@/UI/store";
const coreStore = useCoreStore();

let { MidSurfaceModalVueActive } = storeToRefs(coreStore);

const loading = ref(false);

const providedProps = {
  default: { clearable: true },
  formItem: { required: true },
};

let formModel = {
  midLocation: 50.0,
  midMaxoffset: 0.0,
};

function executeChoosePart() {
  // 选择实体
  coreStore.setEngineState(2);
}

function executeMidSurface() {
  Toast.loading({ content: "抽中面中", duration: 0 });
  loading.value = true;
  _global.Engine.defeature
    .mid_surface({
      location: formModel.midLocation,
      maxoffset: formModel.midMaxoffset,
    })
    .then((result: any) => {
      console.log("result", result);
      coreStore.setBomInfo(result);
      if (result) {
        Message.success("抽取成功");
      }
    })
    .catch((err) => {
      Message.error(err);
    })
    .finally(() => {
      loading.value = false;
      Toast.close();
      coreStore.setEngineState(0);
    });
}
</script>

<style scoped lang="less">
:deep(.vxp-form) {
  display: flex;
  align-items: center;
}
.title {
  display: flex;
  align-items: center;
  margin-bottom: 16px;

  .title_color {
    width: 4px;
    height: 12px;
    background: #339af0;
    margin-right: 8px;
  }
  .title_content {
    opacity: 1;
    font-family: PingFang SC;
    font-size: 14px;
    font-weight: 600;
    line-height: 22px;
    letter-spacing: 0em;
    font-variation-settings: "opsz" auto;
    /* content/主要一级primary */
    /* 样式描述：--vxp-content-color-primary */
    color: #212529;
  }
}
</style>
